#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Apple
{
    public:
        string id;
        int weight;
        int diameter;
        Apple(string pid,int pweight, int pdiameter)
        {
            id = pid;
            weight = pweight;
            diameter = pdiameter;
        }
        friend bool operator<(Apple a1,Apple a2)
        {
            return a1.weight<a2.weight;
        }
};
class Basket
{
    public:
        int id;
        vector<Apple> container;
        Basket(int pid);
        void add(Apple a);
        void showBig();
};
Basket::Basket(int pid)
{
    id = pid;
}
void Basket::add(Apple a)
{
     container.push_back(a);
}
void Basket::showBig()
{
   Apple big = *max_element(container.begin(),container.end());
   cout<<big.id << " "<< big.weight << " "<<big.diameter << endl;
}
int main()
{
    Basket * baskets[1000000] = {NULL};
    int N;
    cin >> N;
    int bid,aw,ad;
    string aid;

    for(int i = 0; i< N; i++)
    {
         cin>>bid>>aid>>aw>>ad;
         Apple apple(aid,aw,ad);
         
         if(baskets[bid] == NULL)
              baskets[bid] = new Basket(bid);
        baskets[bid]->add(apple);
    }
    for(int i = 0; i<1000000; i++)
    {
        if(baskets[i] != NULL)
        {
             cout<<baskets[i]->id<<" ";
             baskets[i]->showBig();
             //用完归还
             delete baskets[i];
             baskets[i] = NULL;
        }
        
    }
    
}